/*
 ------------------------------------------------------------------------------
 Copyright (C) 2009-2011 Eternal Games.

 This file is part of the Eternal Tech source code.

 The Eternal Tech source code is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or (at your
 option) any later version.

 The Eternal Tech source code is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 more details.

 You should have received a copy of the GNU General Public License along with
 the Eternal Tech source code; if not, write to the Free Software Foundation, Inc.,
 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 ------------------------------------------------------------------------------
*/


//
// win_public.h - Public header file to all other systems
//


#if !defined(__WIN_PUBLIC_H__) || !INCLUDE_GUARDS
#define __WIN_PUBLIC_H__


enum cpuId_t {
	CPUID_GENERIC					= BIT(0),	// Unrecognized processor
	CPUID_AMD						= BIT(1),	// AMD processor
	CPUID_INTEL						= BIT(2),	// Intel processor
	CPUID_POWERPC					= BIT(3),	// PowerPC processor
	CPUID_MMX						= BIT(4),	// MMX
	CPUID_MMX_EXT					= BIT(5),	// Extended MMX
	CPUID_3DNOW						= BIT(6),	// 3DNow!
	CPUID_3DNOW_EXT					= BIT(7),	// Extended 3DNow!
	CPUID_SSE						= BIT(8),	// Streaming SIMD Extensions
	CPUID_SSE2						= BIT(9),	// Streaming SIMD Extensions 2
	CPUID_SSE3						= BIT(10),	// Streaming SIMD Extensions 3
	CPUID_SSSE3						= BIT(11),	// Supplemental Streaming SIMD Extensions 3
	CPUID_SSE41						= BIT(12),	// Streaming SIMD Extensions 4.1
	CPUID_SSE42						= BIT(13),	// Streaming SIMD Extensions 4.2
	CPUID_SSE4A						= BIT(14),	// Streaming SIMD Extensions 4A
	CPUID_XOP						= BIT(15),	// XOP
	CPUID_FMA4						= BIT(16),	// Fused Multiply-Add 4
	CPUID_AVX						= BIT(17),	// Advanced Vector Extensions
	CPUID_ALTIVEC					= BIT(18)	// AltiVec
};


/*
 ==============================================================================

    WIN_CONSOLE.CPP

 ==============================================================================
*/

void				Win_CreateConsole ();

void				Win_ConsoleOutput (const char *text);
char				*Win_ConsoleInput ();
void				Win_SetConsoleError (const char *text);
void				Win_ShowConsole (bool show);
void				Win_Printf (const char *fmt);
void				Win_Error (const char *fmt, ...);

void				Win_ShutdownConsole ();

/*
 ==============================================================================

    WIN_EDITORS.CPP

 ==============================================================================
*/

/*
 ==============================================================================

    WIN_EDITORS2.CPP

 ==============================================================================
*/

struct lightProperties_t {
	vec3_t					origin;
	vec3_t					center;
	vec3_t					angles;
	vec3_t					radius;

	int						style;
	int						detailLevel;
	bool					parallel;
	bool					noShadows;

	char					material[MAX_PATH_LENGTH];
	float					materialParms[8];
};

void				Win_SetLightPropertiesCallbacks (void (*updateLight)(lightProperties_t *), void (*removeLight)(), void (*closeLight)());
void				Win_AddLightPropertiesMaterial (const char *name);
void				Win_EditLightProperties (lightProperties_t *lightProperties);
void				Win_ApplyLightProperties ();

void				*Win_CreateLightEditorWindow ();

void				Win_Printf (const char *fmt);
void				Win_Error (const char *fmt, ...);

void				Win_ShutdownLightEditor ();

/*
 ==============================================================================

    WIN_QGL.CPP

 ==============================================================================
*/

void				QGL_EnableLogging (int enable);
void				QGL_LogPrintf (const char *fmt, ...);

/*
 ==============================================================================

    WIN_QAL.CPP

 ==============================================================================
*/

void				QAL_EnableLogging (bool enable);
void				QAL_LogPrintf (const char *fmt, ...);

/*
 ==============================================================================

    WIN_GLW.CPP

 ==============================================================================
*/

#ifdef _WIN32

#define GL_DRIVER_OPENGL				"OpenGL32"	

#define GLImp_SetDeviceGammaRamp		GLW_SetDeviceGammaRamp
#define GLImp_Activate					GLW_Activate
#define GLImp_ActivateContext			GLW_ActivateContext
#define GLImp_SwapBuffers				GLW_SwapBuffers

#define GLImp_Init						GLW_Init
#define GLImp_Shutdown					GLW_Shutdown

struct glwState_t {
	DEVMODE					devMode;

	HWND					hWnd;
	HDC						hDC;
	HGLRC					hGLRC;

	HWND					hWndFake;
	HDC						hDCFake;
	HGLRC					hGLRCFake;

	bool					allowDisplayDepthChange;
	bool					allowDeviceGammaRamp;

	WORD					oldGammaRamp[3][256];
	WORD					newGammaRamp[3][256];

	// FIXME: Remove these when QGL is replaced
	HINSTANCE				hInstOpenGL;
	FILE					*logFile;
};

extern glwState_t			glwState;

void				GLW_SetDeviceGammaRamp (const byte *gammaTable);
void				GLW_Activate (bool active);
void				GLW_ActivateContext (bool active);
void				GLW_SwapBuffers ();

void				GLW_Init ();
void				GLW_Shutdown ();

#else
#error "GLImp not available for this platform"
#endif

/*
 ==============================================================================

    WIN_AL.CPP

 ==============================================================================
*/

#ifdef _WIN32

#define AL_DRIVER_OPENAL				"OpenAL32"

#define ALImp_Init						ALW_Init
#define ALImp_Shutdown					ALW_Shutdown

void				ALW_Init ();
void				ALW_Shutdown ();

#else
#error "ALImp not available for this platform"
#endif

/*
 ==============================================================================

    WIN_MAIN.CPP

 ==============================================================================
*/

const char			**Sys_ListFiles (const char *directory, const char *extension, bool sort, int *numFiles);

void				Sys_FreeFileList (const char **fileList);

const char			*Sys_DefaultBaseDirectory ();

void				Sys_CreateDirectory (const char *directory);

bool				Win_IsWindowFullscreen ();
void				Win_SetEditorWindow (void *wndHandle);

const char			*Win_GetClipboardText ();

int					Win_GetProcessorId ();
int					Win_GetProcessorCount ();
const char			*Win_GetProcessorString ();

void				Win_InitSystem ();
void				Win_ShutdownSystem ();

int					Win_GetEvents ();

void				Win_Exit ();


#else
FILE_WARNING
#endif   // __WIN_PUBLIC_H__